package misc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class FileEnv implements Env {
	
	private ArrayList<Object> m_EnvProperties;
	
	public FileEnv() {
		m_EnvProperties = new ArrayList<Object>();
		m_EnvProperties.add("d:\\Projects\\SSolution\\data\\");
	}

	public String exec(String command, boolean wait) {
		
		String input;
		StringBuffer buffer;
		BufferedReader reader;
		
		buffer = null;
		reader = null;
		
		try {
			reader = new BufferedReader(new FileReader(new File((String) m_EnvProperties.get(0) + command)));
		
			while ((input = reader.readLine()) != null) {
				
				if (buffer == null) {
					buffer = new StringBuffer();
				}
				buffer.append(input);
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			
		} catch (IOException e) {
			e.printStackTrace();
		
		} finally {
			
			try {
				
				if (reader != null) {
					reader.close();
				}
				
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		if (buffer != null) {
			return buffer.toString();
		}
		
		return null;
	}

}
